#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：异步执行例子.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2025/7/18 上午9:19 
"""

import asyncio
import datetime


async def print_datetime():
	cur_datetime = datetime.datetime.now()
	print(cur_datetime)
	await asyncio.sleep(1)
	print(f"{__name__}:print_datetime完成")
	return f"当前时间{cur_datetime}"


async def print_hello():
	content = "Hello"
	print(content)
	await asyncio.sleep(2)
	print(f"{__name__}:print_hello完成")
	return content


async def main():
	print("开始异步执行...")

	# 使用 gather 同时执行两个函数
	results = await asyncio.gather(
		print_datetime(),
		print_hello()
	)

	print("所有函数执行完成，结果：", results)


asyncio.run(main())
